package com.logistic.service.impl;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.logistic.dao.WaybillDao;
import com.logistic.domain.User;
import com.logistic.domain.Waybill;
import com.logistic.page.QueryResult;
import com.logistic.service.WaybillService;


@Service
public class WaybillServiceImpl implements WaybillService {

	@Autowired
	private WaybillDao waybillDao;

	/**
	 * 登录验证
	 * @param user
	 * @return
	 */
	public String checkLogin(User user) {
		User newUser = waybillDao.login(user);
		if(newUser == null) {
			return "error";
		} else {
			
			return newUser.getUid();
		}
	}
	
	public List findRecordAll(String sort)
	{
		List list = new ArrayList();
		list = waybillDao.getAll();
		return list;
	}
	
	public String save(Waybill wb)
	{
		int num = waybillDao.save(wb);
		if(num > 0) {
			return "ok";
		} else {
			return "error";
		}
	}
	
	public void modify(Waybill wb)
	{
		waybillDao.modify(wb);
	}
	
	public void modifyByManager(Waybill wb){
		waybillDao.modifyByManager(wb);
	}
	
	public List searchWaybill(Waybill wb)
	{
		return waybillDao.searchWaybill(wb);
	}
	
	public Waybill getWaybillById(Waybill wb){
		return waybillDao.getWaybillById(wb);
	}
	
	public List getWayillByUid(Waybill wb){
		return waybillDao.getWayillByUid(wb);
	}
	
	public List findWaybillByUidAndStatus(Waybill wb){
		return waybillDao.findWaybillByUidAndStatus(wb);
	}
	
	public List findEnterWaybillNum(String Uid){
		return waybillDao.findEnterWaybillNum(Uid);
	}
	
	public List searchWaybillForecast(Waybill wb)
	{
		return waybillDao.searchWaybillForecast(wb);
	}
	
	public List searchByInput(Waybill wb){
		return waybillDao.searchByInput(wb);
	}
	
	public QueryResult findWaybillsByStatus(String wbArea,String status,int first,int max){
		return waybillDao.findWaybillsByStatus(wbArea,status,first,max);
	}
	
	public List findWaybillsByStatusWithoutPage(Waybill wb)
	{
		return waybillDao.findWaybillsByStatusWithoutPage(wb);
	}
	
	public QueryResult findCurrentWaybillByUid(String Uid,int first,int max){
		return waybillDao.findCurrentWaybillByUid(Uid,first,max);
	}
	
	public QueryResult findHistoryWaybillByUid(String Uid,int first,int max){
		return waybillDao.findHistoryWaybillByUid(Uid,first,max);
	}
	
	public void deleteWaybillById(String wbIds){
		String[] ids = wbIds.split("'"); 
		for(int i = 0; i < ids.length; i++) {
			waybillDao.delete(ids[i]);
		}
	}
	
	public WaybillDao getWaybillDao() {
		return waybillDao;
	}

	public void setWaybillDao(WaybillDao waybillDao) {
		this.waybillDao = waybillDao;
	}
}
